package com.leanit.pmc.login;

import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

/**
 * 用户登录controller
 *
 * @author
 */
@Controller
@RequestMapping("/security")
public class LoginController {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD})
    public String login() {
        return "login";
    }

    @RequestMapping(value = "/logout", method = {RequestMethod.GET, RequestMethod.POST})
    public String logout(HttpSession session) {
        try {
            SecurityUtils.getSubject().logout();
            session.invalidate();
        } catch (Exception e) {
            logger.error("", e);
        }
        return "login";
    }

}
